package com.iot.ammeter.responseResult;

import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @ClassName: ResponseResult
 * @Author: Basil
 * @Date: 2021/9/26 下午2:13
 * @Version: 1.0
 * @Description: 返回封装集
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "返回结果", description = "")
public class ResponseResult {
    /**
     * 是否成功
     */
    private boolean success;
    /**
     * 返回消息提示
     */
    private String message;
    /**
     * 返回状态码
     */
    private String code;
    /**
     * 返回数据
     */
    private Object data;


    public ResponseResult(ResponseState responseState) {
        this.success = responseState.isSuccess();
        this.code = responseState.getCode();
        this.message = responseState.getMessage();
    }

    /**
     * 操作成功
     *
     * @return
     */
    public static ResponseResult SUCCESS() {
        return new ResponseResult(ResponseState.SUCCESS);
    }

    /***
     * 操作失败
     *
     * @return
     */
    public static ResponseResult FAILED() {
        return new ResponseResult(ResponseState.FAILED);
    }

    /**
     * 系统异常
     *
     * @return
     */
    public static ResponseResult SYSTEM_ERROR() {
        return new ResponseResult(ResponseState.SYSTEM_ERROR);
    }

    /**
     * 操作成功
     *
     * @param message
     * @param data
     * @return
     */
    public static ResponseResult SUCCESS(String message, Object data) {
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode("200");
        responseResult.setMessage(message);
        responseResult.setData(data);
        responseResult.setSuccess(true);
        return responseResult;
    }

    /**
     * 操作成功
     *
     * @param data
     * @return
     */
    public static ResponseResult SUCCESS(Object data) {
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode("200");
        responseResult.setMessage("操作成功");
        responseResult.setData(data);
        responseResult.setSuccess(true);
        return responseResult;
    }

    /**
     * 操作失败
     *
     * @param message
     * @return
     */
    public static ResponseResult FAILED(String message) {
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode("400");
        responseResult.setMessage(message);
        responseResult.setSuccess(false);
        return responseResult;
    }

    /**
     * 操作失败
     *
     * @param code
     * @param message
     * @return
     */
    public static ResponseResult FAILED(String code, String message) {
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(code);
        responseResult.setMessage(message);
        responseResult.setSuccess(false);
        return responseResult;
    }
}
